package com.kuangjia.student_ems.dto;

import com.kuangjia.student_ems.entity.SalaryRecord;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class SalaryRecordDTO {
    private Long id;
    private Long userId;
    private String userName;
    private String userDepartment;
    private String userPosition;
    private Integer year;
    private Integer month;
    private Long schemeId;
    private String schemeName;
    private BigDecimal baseSalary;
    private BigDecimal attendanceDeduction;
    private BigDecimal otherDeduction;
    private BigDecimal socialSecurity;
    private BigDecimal housingFund;
    private BigDecimal tax;
    private BigDecimal totalSalary;
    private BigDecimal netSalary;
    private Integer workDays;
    private BigDecimal overtimeHours;
    private BigDecimal performanceScore;
    private String status;
    private String remark;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    public static SalaryRecordDTO fromEntity(SalaryRecord record) {
        SalaryRecordDTO dto = new SalaryRecordDTO();
        dto.setId(record.getId());
        dto.setUserId(record.getUserId());
        dto.setYear(record.getYear());
        dto.setMonth(record.getMonth());
        dto.setSchemeId(record.getSchemeId());
        dto.setBaseSalary(record.getBaseSalary());
        dto.setAttendanceDeduction(record.getAttendanceDeduction());
        dto.setOtherDeduction(record.getOtherDeduction());
        dto.setSocialSecurity(record.getSocialSecurity());
        dto.setHousingFund(record.getHousingFund());
        dto.setTax(record.getTax());
        dto.setTotalSalary(record.getTotalSalary());
        dto.setNetSalary(record.getNetSalary());
        dto.setWorkDays(record.getWorkDays());
        dto.setOvertimeHours(record.getOvertimeHours());
        dto.setPerformanceScore(record.getPerformanceScore());
        dto.setStatus(record.getStatus().name());
        dto.setRemark(record.getRemark());
        dto.setCreateTime(record.getCreateTime());
        dto.setUpdateTime(record.getUpdateTime());
        
        if (record.getUser() != null) {
            dto.setUserName(record.getUser().getName());
            if (record.getUser().getDepartment() != null) {
                dto.setUserDepartment(record.getUser().getDepartment().getName());
            }
            if (record.getUser().getPosition() != null) {
                dto.setUserPosition(record.getUser().getPosition().getName());
            }
        }
        
        if (record.getScheme() != null) {
            dto.setSchemeName(record.getScheme().getName());
        }
        
        return dto;
    }
} 